<template>
	<view class="columnbox wdh-100 content">
		<view class="info-box columnbox wdh-100">
			<view class="rowbox one-info jus">
				<view class="info-title">名称</view>
				<input placeholder-class="reg-pl" class="info-input" v-model="name" placeholder="请输入名称" />
			</view>
			<view class="rowbox one-info jus">
				<view class="info-title">地址</view>
				<input placeholder-class="reg-pl" class="info-input" v-model="area" placeholder="请输入地址" />
			</view>
		</view>
		<view class="info-box columnbox wdh-100">
			<view class="rowbox one-info jus">
				<view class="info-title">logo</view>
				<image v-if="logo==''" @click="addTx" src="/static/img/addimg.png" mode="aspectFill" class="add-img">
				</image>
				<image v-else @click="addTx" :src="logo" mode="aspectFill" class="add-img"></image>
			</view>
		</view>
		<view style="width: 100%;height: 200rpx;"></view>
		<view class="rowbox wdh-100 bottom-box">
			<view v-if="submitflag" class="rowbox wdh-100 send-btn grey-btn" @click="submitInfo">保存</view>
			<view v-else class="rowbox wdh-100 send-btn" @click="submitInfo">保存</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				name: '',
				area: '',
				logo: '',
				submitflag: false
			};
		},
		methods: {
			addTx() {
				uni.chooseImage({
					count: 1,
					success: (res) => {
						this.logo = res.tempFilePaths[0]
					}
				})
			},
			async submitInfo() {
				if (this.name == '') {
					uni.showToast({
						title: '请填写名称',
						icon: 'none'
					})
				}
				// else if (this.area == '') {
				// 	uni.showToast({
				// 		title: '请填写地址',
				// 		icon: 'none'
				// 	})
				// } else if (this.logo == '') {
				// 	uni.showToast({
				// 		title: '请上传logo',
				// 		icon: 'none'
				// 	})
				// } 
				else {
					if (!this.submitflag) {
						this.submitflag = true
						uni.showLoading({
							title: '正在提交',
							mask: true
						})
						let logo = await this.sendImg(this.logo)

						this.$req.post('/doctor/hospitaladd', {
							name: this.name,
							logo: logo,
							area: this.area
						}).then(res => {
							uni.hideLoading()
							if (res.data.code == 0) {
								uni.showModal({
									title: '添加成功',
									content: '',
									success: () => {
										uni.navigateBack()
									}
								})
							} else {
								this.submitflag = false
								uni.showModal({
									title: '提交失败',
									content: res.data.msg
								})
							}
						})
					}
				}
			},
			sendImg(url) {
				return new Promise(resolve => {
					if (url != '') {
						this.$req.uploadImg(url).then(res => {
							resolve(res.data.data)
						})
					} else {
						resolve('')
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		background: #F5F8FB;
		min-height: 100vh;
		justify-content: flex-start;
		font-family: PingFang SC;
	}

	.one-info {
		width: 100%;
		padding: 32rpx 32rpx;
		background: #fff;
		border-bottom: #F5F7F9 solid 1px;
		font-size: 26rpx;

		.info-title {
			font-weight: bold;
			font-size: 26rpx;
			color: #202020;
			width: 170rpx;
			margin-right: 20rpx;
		}



		.info-input {
			width: calc(100% - 190rpx);
			text-align: left;
			font-size: 26rpx;
		}

		.code-box {
			width: calc(100% - 190rpx);
		}

		.code-input {
			text-align: left;
			font-size: 26rpx;
			width: 200rpx;
		}

		.code-btn {
			font-weight: bold;
		}
	}

	.info-box {
		margin-top: 20rpx;
	}

	.add-img {
		width: 140rpx;
		height: 140rpx;
		border-radius: 20rpx;
	}

	.add-img-box {
		width: 140rpx;
		height: 140rpx;
		position: relative;
		margin-right: 20rpx;
		margin-bottom: 20rpx;

		.delet-img {
			position: absolute;
			top: -10rpx;
			right: -10rpx;
			background: #fff;
			border-radius: 100rpx;
		}
	}

	.tag-list {
		height: 90vh;

		.tag-title {
			width: 100%;
			font-weight: bold;
			font-size: 32rpx;
			color: #202020;
			font-family: PingFang SC;
			margin-top: 32rpx;
		}

		.q-title {
			width: 100%;
			font-weight: bold;
			font-size: 28rpx;
			color: #202020;
			font-family: PingFang SC;
			line-height: 40rpx;
			margin-bottom: 20rpx;
			margin-left: 20rpx;
			margin-top: 40rpx;

			text {
				color: #9b9ea0;
				font-size: 26rpx;
			}
		}

		.q-title>view:nth-child(1) {
			position: relative;
			z-index: 4;
		}

		.q-line {
			background: linear-gradient(to right, #00b6b2, rgba(#00b6b2, 0));
			width: 70rpx;
			height: 15rpx;
			margin-top: -15rpx;
		}

		.tag-list-box {
			display: flex;
			flex-wrap: wrap;
			justify-content: flex-start;
			padding: 0 20rpx;
			box-sizing: border-box;
		}
	}

	.jb-list {
		width: calc(100% - 190rpx);
		display: flex;
		flex-wrap: wrap;
		justify-content: flex-start;
	}

	.one-tag,
	.sel-tag {
		border: #dadcdc solid 1px;
		color: #474747;
		font-size: 22rpx;
		margin-bottom: 20rpx;
		margin-right: 20rpx;
		border-radius: 4rpx;
		padding: 4rpx 10rpx;
		line-height: 40rpx;
	}

	.sel-tag {
		border: #00b6b2 solid 1px;
		color: #202020;
		background: rgba(#bfdad9, .1);
	}

	.sel-tag-list {
		display: flex;
		flex-wrap: wrap;
		justify-content: flex-start;
		padding: 0 20rpx;
		box-sizing: border-box;
		background: #F5F8FB;
		padding-top: 20rpx;
	}

	.scjb-list {
		width: calc(100% - 190rpx);
		display: flex;
		flex-wrap: wrap;
		justify-content: flex-start;
	}

	.one-jigou {
		padding: 24rpx 24rpx;

		.jg-img {
			width: 280rpx;
			height: 200rpx;
			border-radius: 16rpx;
			margin-right: 20rpx;
		}

		.jg-name {
			font-weight: 800;
			font-size: 28rpx;
			color: #000000;
		}

		.jg-area {
			font-weight: 400;
			font-size: 24rpx;
			color: #5F5F5F;
			margin-top: 40rpx;
			width: 100%;
		}
	}

	.search-box {
		padding: 32rpx 36rpx;
		background: #fff;

		.search-info {
			width: 100%;
			height: 70rpx;
			border: #00b6b2 solid 1px;
			border-radius: 100rpx;
			padding-left: 20rpx;

			input {
				font-size: 26rpx;
				margin-left: 10rpx;
			}
		}

		.search-btn {
			width: 110rpx;
			height: 50rpx;
			background: linear-gradient(to right, #01a7a1, #5acbc1);
			border-radius: 100rpx;
			font-size: 26rpx;
			color: #fff;
			margin-right: 10rpx;
		}
	}



	.img-list {
		width: calc(100% - 190rpx);
		display: flex;
		flex-wrap: wrap;
		justify-content: flex-start;
	}

	.grey-btn {
		background: #dee3e7;
	}

	.no-search {
		width: 100%;
		font-size: 28rpx;
		margin: 40rpx 0;
	}
</style>